package main;
import java.io.File;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.apache.log4j.spi.RootLogger;

import java.util.logging.FileHandler;

/**
 * Configures the logging system.
 * @author Chunhui Li
 *
 */
/*
abstract class SmeLogging {
	// Make sure this is only initialised once
	private static boolean initialised = false;
	
	// Creates a file handler that outputs everything and add's it to the root logger.
	public static void init() {
		if (SmeLogging.initialised) {
			return;
		}
		else {
			SmeLogging.initialised = true;
		}
		
		try {

			// Get the root logger
			Logger logger = Logger.getLogger("");
			
//			Logger logger = Logger.getLogger("repastcity3");

			// Create handlers
			File logFile = new File("model_log.txt");
			if (logFile.exists())
				logFile.delete(); // Delete an old log file
			FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath());
			fileHandler.setLevel(Level.ALL); // Write everything to the file

			// Create a formatters.
			Formatter fileFormatter = new SimpleFormatter();

			// Add the formatters to the handlers
			fileHandler.setFormatter(fileFormatter);

			// Add the handlers to the logger
			logger.addHandler(fileHandler);

		} catch (Exception e) {
			System.err.println("Problem creating loggers, cannot continue (exit with -1).");
			System.exit(-1);
		}

	}
}*/
public class SmeLogging {
	  static private FileHandler fileTxt;
	  static private SimpleFormatter formatterTxt;

	
	  static public void setup(String s) throws IOException {
   
	    // get the global logger to configure it
	    Logger logger = Logger.getLogger("");

	    // suppress the logging output to the console
//	    Logger rootLogger = Logger.*getLogger*("");
//	    Handler[] handlers = rootLogger.getHandlers();
//	    if (handlers[0] instanceof ConsoleHandler) {
//	      rootLogger.removeHandler(handlers[0]);
//	    }

	    logger.setLevel(Level.INFO);
	    fileTxt = new FileHandler(s);
	   

	    // create a TXT formatter
	    formatterTxt = new SimpleFormatter();
	    fileTxt.setFormatter(formatterTxt);
	    logger.addHandler(fileTxt);

	   
	}
}
	 
